package com.jyh.controller;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author JYH
 * @version 1.0
 * @date 2023/1/3 19:38
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @RequestMapping("info")
    public Authentication info(){
        //获取security和上下文对象
        SecurityContext context = SecurityContextHolder.getContext();
        //用户认证的信息封装到Authentication类中
        Authentication authentication = context.getAuthentication();
        return authentication;
    }
    @RequestMapping("insert")
    @PreAuthorize(value = "hasAuthority('user:insert')")
    public String insert(){
        return "用户添加";
    }
    @RequestMapping("update")
    @PreAuthorize(value = "hasAuthority('user:update')")
    public String update(){
        return "用户修改操作";
    }
    @RequestMapping("query")
    @PreAuthorize(value = "hasAuthority('user:query')")
    public String query(){
        return "用户的查询操作";
    }
    @RequestMapping("delete")
    @PreAuthorize(value = "hasAuthority('user:delete')")
    public String delete(){
        return "用户的删除操作";
    }
    @RequestMapping("export")
    @PreAuthorize(value = "hasAuthority('user:export')")
    public String export(){
        return "用户导出的操作";
    }
}
